package com.mdlib.helper.ui.widget.text;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.ljlib.help.R;
import com.mdlib.helper.model.entity.MessageEntity;

import java.util.List;

/**
 * Created by apple on 16/4/9.
 */
public class LJViewAdapter {
    private List<MessageEntity> mDatas;
    private TextView mTvMessgeContent;


    public LJViewAdapter(List<MessageEntity> mDatas) {
        this.mDatas = mDatas;
        if (mDatas == null || mDatas.isEmpty()) {
            throw new RuntimeException("nothing to show");
        }
    }

    /**
     * 获取数据的条数
     *
     * @return
     */
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    /**
     * 获取摸个数据
     *
     * @param position
     * @return
     */
    public MessageEntity getItem(int position) {
        return mDatas.get(position);
    }

    /**
     * 获取条目布局
     *
     * @param parent
     * @return
     */
    public View getView(LJAdverView parent) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_text, null);
    }

    /**
     * 条目数据适配
     *
     * @param view
     * @param data
     */
    public void setItem(final View view, final MessageEntity data) {
        mTvMessgeContent = (TextView) view.findViewById(R.id.tv_messge_content);
        mTvMessgeContent.setText(data.getContent());

    }
}
